package com.cust.cow.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cust.cow.common.Result;
import com.cust.cow.mapper.CattleAddressBaseMapper;
import com.cust.cow.pojo.cattleAddressBase;
import com.cust.cow.service.CattleAddressBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;

@Service
public class cattleAddressBaseServiceImpl implements CattleAddressBaseService {
    @Autowired
    CattleAddressBaseMapper cattleAddressBaseMapper;
    @Override
    public Result UpdateCattleAddressBase(cattleAddressBase cattleAddressBase) {
        UpdateWrapper<cattleAddressBase> wrapper = new UpdateWrapper<>();
        wrapper.eq("cattle_id", cattleAddressBase.cattleId)
                .set("address", cattleAddressBase.getAddress());

        // 只使用UpdateWrapper进行更新
        int result = cattleAddressBaseMapper.update(cattleAddressBase, wrapper);
        if (result <= 0) {
            return new Result(cattleAddressBase.getCattleId(), cattleAddressBase.getAddress());
        }
        return new Result(200, "更新成功");
    }

    @Override
    public Result insertCattleAddressBase(cattleAddressBase cattleAddressBase) {
        cattleAddressBaseMapper.insert(cattleAddressBase);
        return new Result(200, "插入成功");
    }
}
